﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace AvsBuilderModelNS
{
    class AvsBuilderModel
    {
        private string mediaFilePath;
        private string avsAudioPath;
        private string avsVideoPath;

        private StringBuilder videoFilterStr;

        public AvsBuilderModel(string mediaPath, string outAvsFilesPath) {
            mediaFilePath = mediaPath;
            avsAudioPath = outAvsFilesPath + @"audio.avs";
            avsVideoPath = outAvsFilesPath + @"video.avs";
            videoFilterStr = new StringBuilder();
        }

        public void addResize(int width, int hight) {
            videoFilterStr.AppendLine(String.Format("LanczosResize({0},{1})", width, hight));
        }

        public void addCrop(int startX, int startY, int width, int hight) {
            videoFilterStr.AppendLine(String.Format("Crop({0},{1},{2},{3})", startX, startY, width, hight));
        }

        public void creatAvsFiles() {
            
            StreamWriter audioAvsWriter = new StreamWriter(avsAudioPath,false, Encoding.Default);
            audioAvsWriter.WriteLine(String.Format("DirectshowSource(\"{0}\",video=false)\n", mediaFilePath));
            audioAvsWriter.WriteLine("GetChannel(1,2)");
            audioAvsWriter.Close();


            StreamWriter videoAvsWriter = new StreamWriter(avsVideoPath, false, Encoding.Default);
            videoAvsWriter.WriteLine(String.Format("DirectshowSource(\"{0}\",convertfps=true,audio=false)", mediaFilePath));
            videoAvsWriter.Write(videoFilterStr.ToString());
            videoAvsWriter.Close();
        }
    }
}
